#pragma once

#include "tnet.h"

#include <sys/inotify.h>

namespace tnet
{
    class IOLoop;
    class Inotifyer : public nocopyable
                   , public std::enable_shared_from_this<Inotifyer>
    {
    public:
        Inotifyer(const std::string& path,int option, const InotifyerHandler_t& handler);
        ~Inotifyer();

        static int createInotifyFd(const std::string& path,int notify_option,int& result);

        void start(IOLoop* loop);
        void stop();

        int fd() { return m_fd; }

        IOLoop* loop() { return m_loop; }

    private:
        void onInotify(IOLoop*, int);

    private:
        IOLoop* m_loop;
        int m_fd;
        bool m_running;
        InotifyerHandler_t m_handler;
        std::string m_path;
        int m_result;
    };    
}